<!DOCTYPE html>
<html lang="zn">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>算饭钱-特供</title>
    <!-- 引入样式文件 -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/vant@2.12/lib/index.css"
    />
  </head>
  <body>
    <div id="app">
      <div class="row">
        总金额：
        <input type="number" v-model="totalPrice" />
      </div>
      <div class="row">
        总人数：
        <input type="number" v-model="totalNum" />
      </div>

      <div class="row">
        满减金额：
        <input type="number" v-model="reduced" />
      </div>
      <div v-if="reduced !==0 && totalPrice!==0">
        <div v-for="(item, index) in list" :key="index" class="row">
          <div>
            第 {{index+1}} 个人支付
            <input type="number" v-model="list[index].payPrice" />元
          </div>
          <div v-if="item.payPrice!==0">
            ta要付
            {{(item.payPrice*(totalPrice-reduced)/totalPrice).toFixed(2)}} 元
          </div>
        </div>
      </div>
    </div>
  </body>

  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
  <!-- 引入 Vue 和 Vant 的 JS 文件 -->
  <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script> -->
  <script src="https://cdn.jsdelivr.net/npm/vant@2.12/lib/vant.min.js"></script>

  <script>
    new Vue({
      el: "#app",
      data: {
        price: 0,
        totalPrice: 0,
        totalNum: 0,
        reduced: 0,

        list: [],
      },
      created() {},

      watch: {
        totalNum: function (val) {
          console.log(val);
          let list = [];
          for (let index = 0; index < val; index++) {
            list.push({
              payPrice: 0,
              resPrice: 0,
            });
          }

          //   this.$nextTick(() => {
          this.list = list;
          //   });
        },
      },

      methods: {},
    });

    Vue.use(vant.DatetimePicker);
  </script>

  <style>
    #app {
      display: flex;
      justify-content: center;
      flex-direction: column;
      padding: 30px;
      box-sizing: border-box;
    }

    .row {
      margin-top: 20px;
    }
  </style>
</html>
